import API from '../../utils/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
      dataList:[],
      sum_money:'0',
      showModal: false,
      name:'',
      nameState:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.incomeList()
  },
  incomeList () {
    API.incomeList({productid:wx.getStorageSync('myActivityId')}).then(res=>{
      if (res.code == 0) {
        this.setData({
          sum_money:res.sum_money,
          dataList:res.data
        })
      }
    })
  },
  // 提现
  tixianConditon () {
    this.setData({
      showModal: true
    })
    
  },
  onShow: function () {

  },
  inputChange(e) {
    this.setData({
      name:e.detail.value,
      nameState:false
    })

  },
  /**
   * 弹出框蒙层截断touchmove事件
   */
  preventTouchMove: function () {
  },
  /**
   * 隐藏模态对话框
   */
  hideModal: function () {
    this.setData({
      showModal: false
    });
  },
  /**
   * 对话框取消按钮点击事件
   */
  onCancel: function () {
    this.hideModal();
  },
  /**
   * 对话框确认按钮点击事件
   */
  onConfirm: function () {
    
    if (this.data.name!=='') {
    var data = {
      name:this.data.name,
      aid:wx.getStorageSync('myActivityId')
    }
    API.tixianConditon(data).then(res=>{
      if (res.code == 0) {
        this.hideModal();
        wx.showToast({
          title: '提现成功',
          icon: 'success',
          duration: 2000
        })
      } else {
        wx.showToast({
          title: res.error_msg,
          icon: 'success',
          duration: 3000
        })
      }
    }) 
  } else {
    this.setData({
      nameState:true
    })
  }
  }
})